package session.stateless;

import entity.SaleQuotation;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless

public class SaleQuotationBean implements SaleQuotationBeanLocal {
    @PersistenceContext()
    EntityManager em;
    SaleQuotation saleQuotation;

    public void createNewSaleQuotation() {
        SaleQuotation saleQuotation = new SaleQuotation();
        //Add dependencies
        em.persist(saleQuotation);
    }

    public void updateSaleQuotation(long saleQuotationId) {
        saleQuotation = em.find(SaleQuotation.class, saleQuotationId);
        //make changes        
    }

    public void deleteSaleQuotation(long saleQuotationId) {
        saleQuotation =em.find(SaleQuotation.class, saleQuotationId);
        if (saleQuotation ==null)
            System.out.println("Hi!");
        else
        {
            //make changes
            em.remove(saleQuotation);
        }
    }

    public List<SaleQuotation> getSaleQuotation() {
        Query q = em.createQuery("SELECT c FROM SaleQuotation c");
        List<SaleQuotation> saleQuotations = new ArrayList<SaleQuotation>();
        for (Object o: q.getResultList() )
        {
            SaleQuotation saleQuotation = (SaleQuotation) o;
            saleQuotations.add(saleQuotation);
        }
        return saleQuotations;
    }

    public List<SaleQuotation> getSaleQuotationBySaleLead(long saleLeadId) {
        
        //this method didnt take into consideration of specific SaleLead
        Query q = em.createQuery("SELECT c FROM SaleQuotation c");
        List<SaleQuotation> saleQuotations = new ArrayList<SaleQuotation>();
        for (Object o: q.getResultList() )
        {
            SaleQuotation saleQuotation = (SaleQuotation) o;
            saleQuotations.add(saleQuotation);
        }
        return saleQuotations;
        }
}